package com.wyix.service.impl;

import org.springframework.stereotype.Service;

/**
 * @author wangdx
 * @since 2025/8/6
 */
@Service
public class OrderService {
    public void createOrder(Long userId) {
        System.out.println("为用户" + userId + "创建订单");
    }

    // 模拟下单操作
    public String createOrder(String userId, String productId) {
        System.out.println("执行下单逻辑：用户【" + userId + "】购买商品【" + productId + "】");
        return "ORDER_" + System.currentTimeMillis();  // 返回订单号
    }

    // 模拟查询订单
    public String queryOrder(String orderId) {
        if (orderId == null) throw new IllegalArgumentException("订单号不能为空");
        return "订单详情：订单号【" + orderId + "】，状态：已支付";
    }

    // 返回值为对象的方法
    public Order createOrder(Long userId, Long bookId) {
        return new Order(1001L, userId, bookId, 99.9);
    }

    static class Order {
        private Long orderId;
        private Long userId;
        private Long bookId;
        private double amount;

        public Order(Long orderId, Long userId, Long bookId, double amount) {
            this.orderId = orderId;
            this.userId = userId;
            this.bookId = bookId;
            this.amount = amount;
        }

        public Long getOrderId() {
            return orderId;
        }

        public void setOrderId(Long orderId) {
            this.orderId = orderId;
        }

        public Long getUserId() {
            return userId;
        }

        public void setUserId(Long userId) {
            this.userId = userId;
        }

        public Long getBookId() {
            return bookId;
        }

        public void setBookId(Long bookId) {
            this.bookId = bookId;
        }

        public double getAmount() {
            return amount;
        }

        public void setAmount(double amount) {
            this.amount = amount;
        }
    }
}
